package exception;

public class TryCatchDemo {
    public static void main(String[] args) {
        System.out.println("程序开始了");

        //try中代码不出现下述异常，catch不会执行
        try {
            String str = "a";
            String line = "a";
            System.out.println(str.length());
            System.out.println(str.charAt(0));
            System.out.println(Integer.parseInt(line));
            System.out.println("!!!!!!!!!!!!!!!!");
        }catch (NullPointerException | IndexOutOfBoundsException e){
            System.out.println("出现了空指针或下标越界异常并解决了");
        }catch (Exception e){
            System.out.println("反正就是出现了错");
        }
        /*catch (NullPointerException e){
            System.out.println("空指针问题解决了");
            //catch可以定义多个，针对不同的异常有不同的解决办法
        }catch (IndexOutOfBoundsException e){
            System.out.println("下标越界解决了");
        }*/

        System.out.println("程序结束了");
    }
}
